﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Navigation;

namespace Mapping_Demo
{
    public class LaunchUriMapper : UriMapperBase
    {
        private string tempUri;

        public override Uri MapUri(Uri uri)
        {
            tempUri = System.Net.HttpUtility.UrlDecode(uri.ToString());

            // URI association launch for storagedemo
            if (tempUri.Contains("mapdemo:"))
            {
                if (tempUri.Contains("?subpage="))
                {
                    int pageIndex = tempUri.IndexOf("?subpage=") + 9;
                    string pageIDString = tempUri.Substring(pageIndex);
                    if (pageIDString == "1")
                    {
                        return new Uri("/Views/SimpleDistance.xaml", UriKind.Relative);
                    }
                    else if (pageIDString == "2")
                    {
                        return new Uri("/Views/ReverseGeoCode.xaml", UriKind.Relative);
                    }
                    else if (pageIDString == "3")
                    {
                        return new Uri("/Views/ScavengerHunt.xaml", UriKind.Relative);
                    }
                    else if (pageIDString == "4")
                    {
                        return new Uri("/Views/IsMapOffline.xaml", UriKind.Relative);
                    }
                }

                return new Uri("/MainPage.xaml", UriKind.Relative);
            }

            // Otherwise perform normal launch.
            return uri;
        }
    }
}
